package it.polimi.travelDream.web.beans;

import it.polimi.it.TravelDream.entities.BasicProdMgr;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;	

import it.polimi.it.TravelDream.ejb.UserMgr;
import it.polimi.it.TravelDream.ejb.eaos.FlightDTO;

	@ManagedBean
	@RequestScoped
	public class SearchFlightBean {
		
		@EJB
		private BasicProdMgr basicProdMgr;
		
		@EJB
		private UserMgr userMgr;
		
		private List<FlightDTO> flightsList;
		
		private List<FlightDTO> flightsFiltered;
		
		private FlightDTO selectedFlight; 

		
		
		
		public FlightDTO getSelectedFlight() {
			return selectedFlight;
		}
		
		public void setSelectedFlight(FlightDTO selectedFlight) {
			this.selectedFlight = selectedFlight;
		}

		
		public List<FlightDTO> getFlightsFiltered() {
			return flightsFiltered;
		}
		public void setFlightsFiltered(List<FlightDTO> flightsFiltered) {
			this.flightsFiltered = flightsFiltered;
		}
		
		
		public List<FlightDTO> getFlightsList() {
			return flightsList;
		}
		public void setFlightsList(List<FlightDTO> flightsList) {
			this.flightsList = flightsList;
		}
		
		@PostConstruct
		public void getAllFlights(){
			flightsList= new ArrayList<FlightDTO>();
			System.out.println("*********io sono il volo");
			flightsList=basicProdMgr.getFlightsList();
			System.out.println("*********io sono il volo");
		}
		
		public void purchaseFlight(){
			selectedFlight.setIdBuyer(userMgr.getUserDTO().getEmail());
			basicProdMgr.purchase(selectedFlight);
			
		}
		
}
